/**
 * Copyright (C) 2008 aileron.cc
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
package cc.aileron.commons.logging;

import static com.google.inject.matcher.Matchers.any;

import java.util.Properties;

import com.google.inject.Binder;
import com.google.inject.Module;

/**
 * logging module
 * @author Aileron
 *
 */
public class LoggingModule implements Module
{
	/**
	 * log-level
	 */
	private final LoggingLevel level ;
	
	/**
	 * logging-interface
	 */
	private final LoggingInterface loggingInterface;
	
	/**
	 * setting
	 */
	private final Properties setting;
	
	/**
	 * log-level 設定
	 * @param type
	 */
	public LoggingModule(
		final LoggingLevel level,
		final Properties setting,
		final LoggingInterface loggingInterface)
	{
		this.level = level;
		this.setting = setting;
		this.loggingInterface = loggingInterface;
	}
	
	/**
	 * log-level設定（LoggingInterfaceはdefaultを使用）
	 * @param level
	 */
	public LoggingModule(
	        final LoggingLevel level,
	        final Properties setting)
	{
	    this.level = level;
	    this.setting = setting;
	    this.loggingInterface = new LoggingInterfaceDefault();
	}
	
	
	public void configure(final Binder binder) 
	{
		if(level.equals(LoggingLevel.NONE))
		{
			return;
		}
		binder.bind(LoggingLevel.class).toInstance(level);
		binder.bindInterceptor(any(), any(), new LoggingInterceptor(level,setting,loggingInterface));
	}
}
